//
//  HomeCell.m
//  BasePorject_App
//
//  Created by Yutian Duan on 2019/5/27.
//  Copyright © 2019年 Wanwin. All rights reserved.
//

#import "HomeCell.h"

@implementation HomeCell

- (void)awakeFromNib {
  [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  [super setSelected:selected animated:animated];
  
  // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  if (self) {
    self.backgroundColor = HEXCOLOR(0xf7f8fc);
  }
  return self;
}

- (UIView *)bgView {
  if (!_bgView) {
    _bgView = [[UIView alloc] init];
    _bgView.backgroundColor = HEXCOLOR(0xfefffe);
    _bgView.layer.masksToBounds = YES;
    _bgView.layer.cornerRadius = 8.0f;
    [self.contentView addSubview:_bgView];
    
    [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
      make.leading.mas_equalTo(self.contentView).offset(20);
      make.top.mas_equalTo(self.contentView.mas_top);
      make.bottom.mas_equalTo(self.contentView).offset(-10);
      make.trailing.mas_equalTo(self.contentView).offset(-20);
    }];
  }
  return _bgView;
}

- (UIImageView *)coverImageView {
  if (!_coverImageView) {
    _coverImageView = [[UIImageView alloc] init];
    [self.bgView addSubview:_coverImageView];
    
    [_coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
      make.leading.trailing.top.mas_equalTo(self.bgView);
      make.height.mas_equalTo(self.coverImageView.mas_width).multipliedBy(IMAGEPRO);
    }];
  }
  return _coverImageView;
}

- (UILabel *)titleLabel {
  if (!_titleLabel) {
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
    _titleLabel.textColor = [UIColor blackColor];
    [self.bgView addSubview:_titleLabel];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
      make.leading.mas_equalTo(self.coverImageView.mas_leading).offset(10);
      make.top.mas_equalTo(self.coverImageView.mas_bottom);
      make.bottom.mas_equalTo(self.bgView);
      make.trailing.mas_equalTo(self.timeLabel.mas_leading);
    }];
  }
  return _titleLabel;
}

- (UILabel *)timeLabel {
  if (!_timeLabel) {
    _timeLabel = [[UILabel alloc] init];
    _timeLabel.font = [UIFont systemFontOfSize:14.0f];
    _timeLabel.textColor = HEXCOLOR(0x666666);
    _timeLabel.textAlignment = NSTextAlignmentRight;
    [self.bgView addSubview:_timeLabel];
    
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
      make.top.bottom.mas_equalTo(self.titleLabel);
      make.trailing.mas_equalTo(self.coverImageView.mas_trailing).offset(-10);
      make.leading.mas_equalTo(self.titleLabel.mas_trailing);
    }];
  }
  return _timeLabel;
}

- (void)setModel:(Home_noticeListModel *)model {
  _model = model;
  [self setupView];
}

- (void)setupView {
  
  self.coverImageView.image = [UIImage imageNamed:@"home_最新消息_01"];
  self.titleLabel.text = @"教你这样用油钱游香港";
  self.timeLabel.text = @"12小时前";
  
}

@end
